package com.gxa.controller.investment;

import com.github.pagehelper.PageInfo;
import com.gxa.common.utils.Result;
import com.gxa.dto.investmentDto.OccupancyRegisterQuitDto;
import com.gxa.entity.investment.OccupancyRegister;
import com.gxa.service.investment.OccupancyRegisterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 入驻登记单 前端控制器
 * </p>
 *
 * @author yjl
 * @since 2022-10-17 03:04:36
 */
@Api(tags = "过程管理/入驻管理")
@RestController
@RequestMapping("/occupancy/register")
public class OccupancyRegisterController {

    @Autowired
    private OccupancyRegisterService occupancyRegisterService;

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("列表接口(条件查询出问题时使用)")
    @GetMapping("/list")
    public Result seletAll(){
        try {
            return Result.success(occupancyRegisterService.seletAll());
        }catch (Exception e){
            e.printStackTrace();
        }
        return Result.failed("seletAll");
    }


    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("增加接口")
    @PostMapping("/add")
    public Result add(@RequestBody OccupancyRegister occupancyRegister){
        try {
            occupancyRegisterService.add(occupancyRegister);
            return Result.success("add success");
        }catch (Exception e){
            e.printStackTrace();
        }
        return Result.failed("add failed");
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("修改状态接口")
    @PutMapping("/update/{id}/{state}")
    public Result update(@PathVariable("id") Integer id, @PathVariable("state") Integer state){
        try {
            occupancyRegisterService.updateToState(id, state);
            return Result.success("update success");
        }catch (Exception e){
            e.printStackTrace();
        }
        return Result.failed("update failed");
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("按id查询")
    @GetMapping("/quit/{id}")
    public Result quitById(@PathVariable("id") Integer id){
        try {
            return Result.success(occupancyRegisterService.quitById(id));
        }catch (Exception e){
            e.printStackTrace();
        }
        return Result.failed("quitById failed");
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("按条件查询")
    @PostMapping("/quit")
    public Result quit(@RequestBody OccupancyRegisterQuitDto occupancyRegisterQuitDto, Integer pageNum, Integer pageSize){

        try {
            PageInfo result = occupancyRegisterService.queryByOccupancyRegisterQuitDto(occupancyRegisterQuitDto, pageNum, pageSize);

            return Result.success(result);
        }catch (Exception e){
            e.printStackTrace();
            return Result.failed("query failed");
        }

    }
}
